home *** CD-ROM | disk | FTP | other *** search
/ Sprite 1984 - 1993 / Sprite 1984 - 1993.iso / src / machserver / 1.098 / dev / ds3100.md / devDC7085.c < prev    next >
Text File  |  1989-08-29  |  23KB  |  928 lines

  1. /* 
  2.  *  devDC7085.c --
  3.  *
  4.  *         This file contains machine-dependent routines that handle the
  5.  *    output queue for the serial lines.
  6.  *
  7.  *    Copyright (C) 1989 Digital Equipment Corporation.
  8.  *    Permission to use, copy, modify, and distribute this software and
  9.  *    its documentation for any purpose and without fee is hereby granted,
  10.  *    provided that the above copyright notice appears in all copies.  
  11.  *    Digital Equipment Corporation makes no representations about the
  12.  *    suitability of this software for any purpose.  It is provided "as is"
  13.  *    without express or implied warranty.
  14.  */
  15.  
  16. #ifndef lint
  17. static char rcsid[] = "$Header: /sprite/src/kernel/dev/ds3100.md/RCS/devDC7085.c,v 1.4 89/08/29 11:55:30 nelson Exp $ SPRITE (DECWRL)";
  18. #endif not lint
  19.  
  20. #include "sprite.h"
  21. #include "machMon.h"
  22. #include "mach.h"
  23. #include "dev.h"
  24. #include "fs.h"
  25. #include "sys.h"
  26. #include "sync.h"
  27. #include "timer.h"
  28. #include "dbg.h"
  29. #include "dc7085.h"
  30. #include "graphics.h"
  31. #include "machAddrs.h"
  32. #include "console.h"
  33. #include <sgtty.h>
  34.  
  35. static Sync_Semaphore dc7085Mutex = Sync_SemInitStatic("Dev:dc7085Mutex");
  36.  
  37. /*
  38.  * Define the six registers.
  39.  */
  40. #define REG_ADDR(offset) (unsigned short *)(MACH_SERIAL_INTERFACE_ADDR + (offset))
  41. static volatile unsigned short *csrPtr =  REG_ADDR(0x00);
  42. static volatile unsigned short *rBufPtr = REG_ADDR(0x08);
  43. static volatile unsigned short *lprPtr =  REG_ADDR(0x08);
  44. static volatile unsigned short *tcrPtr =  REG_ADDR(0x10);
  45. static volatile unsigned short *msrPtr =  REG_ADDR(0x18);
  46. static volatile unsigned short *tdrPtr =  REG_ADDR(0x18);
  47.  
  48. /*
  49.  * The current status of the break bits.
  50.  */
  51. unsigned breakVal = 0;
  52.  
  53. /*
  54.  * Tables mapping sgttyb baud-rate values to actual integers and lpr register
  55.  * values.
  56.  */
  57. static struct {
  58.     int regVal;                /* Value to set in lpr register. */
  59.     int sgttybVal;            /* Baud value from sgtyb. */
  60.     int baud;                /* Integer baud rate. */
  61. } baudMap[] = {
  62.     {0, 0, 0},
  63.     {LPR_B50, B50, 50},
  64.     {LPR_B75, B75, 75},
  65.     {LPR_B110, B110, 110},
  66.     {LPR_B134, B134, 134},
  67.     {LPR_B150, B150, 150},
  68.     {-1, B200, 200},
  69.     {LPR_B300, B300, 300},
  70.     {LPR_B600, B600, 600},
  71.     {LPR_B1200, B1200, 1200},
  72.     {LPR_B2400, B2400, 2400},
  73.     {LPR_B4800, B4800, 4800},
  74.     {LPR_B9600, B9600, 9600}, 
  75.     {-1, -1, -1}
  76. };
  77.  
  78. /*
  79.  * Ascii values of command keys.
  80.  */
  81. #define KBD_TAB        '\t'
  82. #define KBD_DEL        127
  83. #define KBD_RET        '\r'
  84.  
  85. /*
  86.  *  Define "hardware-independent" codes for the control, shift, meta and 
  87.  *  function keys.  Codes start after the last 7-bit ASCII code (127)
  88.  *  and are assigned in an arbitrary order.
  89.  */
  90. #define KBD_NOKEY    128
  91. #define KBD_UNKNOWN    129
  92.  
  93. #define KBD_F1        201
  94. #define KBD_F2        202
  95. #define KBD_F3        203
  96. #define KBD_F4        204
  97. #define KBD_F5        205
  98. #define KBD_F6        206
  99. #define KBD_F7        207
  100. #define KBD_F8        208
  101. #define KBD_F9        209
  102. #define KBD_F10        210
  103. #define KBD_F11        211
  104. #define KBD_F12        212
  105. #define KBD_F13        213
  106. #define KBD_F14        214
  107. #define KBD_HELP    215
  108. #define KBD_DO        216
  109. #define KBD_F17        217
  110. #define KBD_F18        218
  111. #define KBD_F19        219
  112. #define KBD_F20        220
  113.  
  114. #define KBD_FIND    221
  115. #define KBD_INSERT    222
  116. #define KBD_REMOVE    223
  117. #define KBD_SELECT    224
  118. #define KBD_PREVIOUS    225
  119. #define KBD_NEXT    226
  120.  
  121. #define KBD_KP_ENTER    227
  122. #define KBD_KP_F1    228
  123. #define KBD_KP_F2    229
  124. #define KBD_KP_F3    230
  125. #define KBD_KP_F4    231
  126. #define KBD_LEFT    232
  127. #define KBD_RIGHT    233
  128. #define KBD_DOWN    234
  129. #define KBD_UP        235
  130.  
  131. #define KBD_CONTROL    236
  132. #define KBD_SHIFT    237
  133. #define KBD_CAPSLOCK    238
  134. #define KBD_ALTERNATE    239
  135.  
  136. #define KBD_MAX_VALUE    KBD_ALTERNATE
  137.  
  138. /*
  139.  * Keyboard to Ascii, unshifted. 
  140.  */
  141. static unsigned char unshiftedAscii[] = {
  142. /*  0 */ KBD_NOKEY,    KBD_NOKEY,    KBD_NOKEY,    KBD_NOKEY,
  143. /*  4 */ KBD_NOKEY,    KBD_NOKEY,    KBD_NOKEY,    KBD_NOKEY,
  144. /*  8 */ KBD_NOKEY,    KBD_NOKEY,    KBD_NOKEY,    KBD_NOKEY,
  145. /*  c */ KBD_NOKEY,    KBD_NOKEY,    KBD_NOKEY,    KBD_NOKEY,
  146. /* 10 */ KBD_NOKEY,    KBD_NOKEY,    KBD_NOKEY,    KBD_NOKEY,
  147. /* 14 */ KBD_NOKEY,    KBD_NOKEY,    KBD_NOKEY,    KBD_NOKEY,
  148. /* 18 */ KBD_NOKEY,    KBD_NOKEY,    KBD_NOKEY,    KBD_NOKEY,
  149. /* 1c */ KBD_NOKEY,    KBD_NOKEY,    KBD_NOKEY,    KBD_NOKEY,
  150. /* 20 */ KBD_NOKEY,    KBD_NOKEY,    KBD_NOKEY,    KBD_NOKEY,
  151. /* 24 */ KBD_NOKEY,    KBD_NOKEY,    KBD_NOKEY,    KBD_NOKEY,
  152. /* 28 */ KBD_NOKEY,    KBD_NOKEY,    KBD_NOKEY,    KBD_NOKEY,
  153. /* 2c */ KBD_NOKEY,    KBD_NOKEY,    KBD_NOKEY,    KBD_NOKEY,
  154. /* 30 */ KBD_NOKEY,    KBD_NOKEY,    KBD_NOKEY,    KBD_NOKEY,
  155. /* 34 */ KBD_NOKEY,    KBD_NOKEY,    KBD_NOKEY,    KBD_NOKEY,
  156. /* 38 */ KBD_NOKEY,    KBD_NOKEY,    KBD_NOKEY,    KBD_NOKEY,
  157. /* 3c */ KBD_NOKEY,    KBD_NOKEY,    KBD_NOKEY,    KBD_NOKEY,
  158. /* 40 */ KBD_NOKEY,    KBD_NOKEY,    KBD_NOKEY,    KBD_NOKEY,
  159. /* 44 */ KBD_NOKEY,    KBD_NOKEY,    KBD_NOKEY,    KBD_NOKEY,
  160. /* 48 */ KBD_NOKEY,    KBD_NOKEY,    KBD_NOKEY,    KBD_NOKEY,
  161. /* 4c */ KBD_NOKEY,    KBD_NOKEY,    KBD_NOKEY,    KBD_NOKEY,
  162. /* 50 */ KBD_NOKEY,    KBD_NOKEY,    KBD_NOKEY,    KBD_NOKEY,
  163. /* 54 */ KBD_NOKEY,    KBD_NOKEY,    KBD_F1,        KBD_F2,
  164. /* 58 */ KBD_F3,    KBD_F4,        KBD_F5,        KBD_NOKEY,
  165. /* 5c */ KBD_NOKEY,    KBD_NOKEY,    KBD_NOKEY,    KBD_NOKEY,
  166. /* 60 */ KBD_NOKEY,    KBD_NOKEY,    KBD_NOKEY,    KBD_NOKEY,
  167. /* 64 */ KBD_F6,    KBD_F7,        KBD_F8,        KBD_F9,
  168. /* 68 */ KBD_F10,    KBD_NOKEY,    KBD_NOKEY,    KBD_NOKEY,
  169. /* 6c */ KBD_NOKEY,    KBD_NOKEY,    KBD_NOKEY,    KBD_NOKEY,
  170. /* 70 */ KBD_NOKEY,    KBD_F11,    KBD_F12,    KBD_F13,
  171. /* 74 */ KBD_F14,    KBD_NOKEY,    KBD_NOKEY,    KBD_NOKEY,
  172. /* 78 */ KBD_NOKEY,    KBD_NOKEY,    KBD_NOKEY,    KBD_NOKEY,
  173. /* 7c */ KBD_HELP,    KBD_DO,        KBD_NOKEY,    KBD_NOKEY,
  174. /* 80 */ KBD_F17,    KBD_F18,    KBD_F19,    KBD_F20,
  175. /* 84 */ KBD_NOKEY,    KBD_NOKEY,    KBD_NOKEY,    KBD_NOKEY,
  176. /* 88 */ KBD_NOKEY,    KBD_NOKEY,    KBD_FIND,    KBD_INSERT,
  177. /* 8c */ KBD_REMOVE,    KBD_SELECT,    KBD_PREVIOUS,    KBD_NEXT,
  178. /* 90 */ KBD_NOKEY,    KBD_NOKEY,    '0',        KBD_NOKEY,
  179. /* 94 */ '.',        KBD_KP_ENTER,    '1',        '2',
  180. /* 98 */ '3',        '4',        '5',        '6',
  181. /* 9c */ ',',        '7',        '8',        '9',
  182. /* a0 */ '-',        KBD_KP_F1,    KBD_KP_F2,    KBD_KP_F3,
  183. /* a4 */ KBD_KP_F4,    KBD_NOKEY,    KBD_NOKEY,    KBD_LEFT,
  184. /* a8 */ KBD_RIGHT,    KBD_DOWN,     KBD_UP,        KBD_NOKEY,
  185. /* ac */ KBD_NOKEY,    KBD_NOKEY,    KBD_SHIFT,    KBD_CONTROL,
  186. /* b0 */ KBD_CAPSLOCK,    KBD_ALTERNATE,    KBD_NOKEY,    KBD_NOKEY,
  187. /* b4 */ KBD_NOKEY,    KBD_NOKEY,    KBD_NOKEY,    KBD_NOKEY,
  188. /* b8 */ KBD_NOKEY,    KBD_NOKEY,    KBD_NOKEY,    KBD_NOKEY,
  189. /* bc */ KBD_DEL,    KBD_RET,    KBD_TAB,    '`',
  190. /* c0 */ '1',        'q',        'a',        'z',
  191. /* c4 */ KBD_NOKEY,    '2',        'w',        's',
  192. /* c8 */ 'x',        '<',        KBD_NOKEY,    '3',
  193. /* cc */ 'e',        'd',        'c',        KBD_NOKEY,
  194. /* d0 */ '4',        'r',        'f',        'v',
  195. /* d4 */ ' ',        KBD_NOKEY,    '5',        't',
  196. /* d8 */ 'g',        'b',        KBD_NOKEY,    '6',
  197. /* dc */ 'y',        'h',        'n',        KBD_NOKEY,
  198. /* e0 */ '7',        'u',        'j',        'm',
  199. /* e4 */ KBD_NOKEY,    '8',        'i',        'k',
  200. /* e8 */ ',',        KBD_NOKEY,    '9',        'o',
  201. /* ec */ 'l',        '.',        KBD_NOKEY,    '0',
  202. /* f0 */ 'p',        KBD_NOKEY,    ';',        '/',
  203. /* f4 */ KBD_NOKEY,    '=',        ']',        '\\',
  204. /* f8 */ KBD_NOKEY,    '-',        '[',        '\'',
  205. /* fc */ KBD_NOKEY,    KBD_NOKEY,    KBD_NOKEY,    KBD_NOKEY,
  206. };
  207.  
  208. /*
  209.  * Keyboard to Ascii, shifted.
  210.  */
  211. static unsigned char shiftedAscii[] = {
  212. /*  0 */ KBD_NOKEY,    KBD_NOKEY,    KBD_NOKEY,    KBD_NOKEY,
  213. /*  4 */ KBD_NOKEY,    KBD_NOKEY,    KBD_NOKEY,    KBD_NOKEY,
  214. /*  8 */ KBD_NOKEY,    KBD_NOKEY,    KBD_NOKEY,    KBD_NOKEY,
  215. /*  c */ KBD_NOKEY,    KBD_NOKEY,    KBD_NOKEY,    KBD_NOKEY,
  216. /* 10 */ KBD_NOKEY,    KBD_NOKEY,    KBD_NOKEY,    KBD_NOKEY,
  217. /* 14 */ KBD_NOKEY,    KBD_NOKEY,    KBD_NOKEY,    KBD_NOKEY,
  218. /* 18 */ KBD_NOKEY,    KBD_NOKEY,    KBD_NOKEY,    KBD_NOKEY,
  219. /* 1c */ KBD_NOKEY,    KBD_NOKEY,    KBD_NOKEY,    KBD_NOKEY,
  220. /* 20 */ KBD_NOKEY,    KBD_NOKEY,    KBD_NOKEY,    KBD_NOKEY,
  221. /* 24 */ KBD_NOKEY,    KBD_NOKEY,    KBD_NOKEY,    KBD_NOKEY,
  222. /* 28 */ KBD_NOKEY,    KBD_NOKEY,    KBD_NOKEY,    KBD_NOKEY,
  223. /* 2c */ KBD_NOKEY,    KBD_NOKEY,    KBD_NOKEY,    KBD_NOKEY,
  224. /* 30 */ KBD_NOKEY,    KBD_NOKEY,    KBD_NOKEY,    KBD_NOKEY,
  225. /* 34 */ KBD_NOKEY,    KBD_NOKEY,    KBD_NOKEY,    KBD_NOKEY,
  226. /* 38 */ KBD_NOKEY,    KBD_NOKEY,    KBD_NOKEY,    KBD_NOKEY,
  227. /* 3c */ KBD_NOKEY,    KBD_NOKEY,    KBD_NOKEY,    KBD_NOKEY,
  228. /* 40 */ KBD_NOKEY,    KBD_NOKEY,    KBD_NOKEY,    KBD_NOKEY,
  229. /* 44 */ KBD_NOKEY,    KBD_NOKEY,    KBD_NOKEY,    KBD_NOKEY,
  230. /* 48 */ KBD_NOKEY,    KBD_NOKEY,    KBD_NOKEY,    KBD_NOKEY,
  231. /* 4c */ KBD_NOKEY,    KBD_NOKEY,    KBD_NOKEY,    KBD_NOKEY,
  232. /* 50 */ KBD_NOKEY,    KBD_NOKEY,    KBD_NOKEY,    KBD_NOKEY,
  233. /* 54 */ KBD_NOKEY,    KBD_NOKEY,    KBD_F1,        KBD_F2,
  234. /* 58 */ KBD_F3,    KBD_F4,        KBD_F5,        KBD_NOKEY,
  235. /* 5c */ KBD_NOKEY,    KBD_NOKEY,    KBD_NOKEY,    KBD_NOKEY,
  236. /* 60 */ KBD_NOKEY,    KBD_NOKEY,    KBD_NOKEY,    KBD_NOKEY,
  237. /* 64 */ KBD_F6,    KBD_F7,        KBD_F8,        KBD_F9,
  238. /* 68 */ KBD_F10,    KBD_NOKEY,    KBD_NOKEY,    KBD_NOKEY,
  239. /* 6c */ KBD_NOKEY,    KBD_NOKEY,    KBD_NOKEY,    KBD_NOKEY,
  240. /* 70 */ KBD_NOKEY,    KBD_F11,    KBD_F12,    KBD_F13,
  241. /* 74 */ KBD_F14,    KBD_NOKEY,    KBD_NOKEY,    KBD_NOKEY,
  242. /* 78 */ KBD_NOKEY,    KBD_NOKEY,    KBD_NOKEY,    KBD_NOKEY,
  243. /* 7c */ KBD_HELP,    KBD_DO,        KBD_NOKEY,    KBD_NOKEY,
  244. /* 80 */ KBD_F17,    KBD_F18,    KBD_F19,    KBD_F20,
  245. /* 84 */ KBD_NOKEY,    KBD_NOKEY,    KBD_NOKEY,    KBD_NOKEY,
  246. /* 88 */ KBD_NOKEY,    KBD_NOKEY,    KBD_FIND,    KBD_INSERT,
  247. /* 8c */ KBD_REMOVE,    KBD_SELECT,    KBD_PREVIOUS,    KBD_NEXT,
  248. /* 90 */ KBD_NOKEY,    KBD_NOKEY,    '0',        KBD_NOKEY,
  249. /* 94 */ '.',        KBD_KP_ENTER,    '1',        '2',
  250. /* 98 */ '3',        '4',        '5',        '6',
  251. /* 9c */ ',',        '7',        '8',        '9',
  252. /* a0 */ '-',        KBD_KP_F1,    KBD_KP_F2,    KBD_KP_F3,
  253. /* a4 */ KBD_KP_F4,    KBD_NOKEY,    KBD_NOKEY,    KBD_LEFT,
  254. /* a8 */ KBD_RIGHT,    KBD_DOWN,     KBD_UP,        KBD_NOKEY,
  255. /* ac */ KBD_NOKEY,    KBD_NOKEY,    KBD_SHIFT,    KBD_CONTROL,
  256. /* b0 */ KBD_CAPSLOCK,    KBD_ALTERNATE,    KBD_NOKEY,    KBD_NOKEY,
  257. /* b4 */ KBD_NOKEY,    KBD_NOKEY,    KBD_NOKEY,    KBD_NOKEY,
  258. /* b8 */ KBD_NOKEY,    KBD_NOKEY,    KBD_NOKEY,    KBD_NOKEY,
  259. /* bc */ KBD_DEL,    KBD_RET,    KBD_TAB,    '~',
  260. /* c0 */ '!',        'q',        'a',        'z',
  261. /* c4 */ KBD_NOKEY,    '@',        'w',        's',
  262. /* c8 */ 'x',        '>',        KBD_NOKEY,    '#',
  263. /* cc */ 'e',        'd',        'c',        KBD_NOKEY,
  264. /* d0 */ '$',        'r',        'f',        'v',
  265. /* d4 */ ' ',        KBD_NOKEY,    '%',        't',
  266. /* d8 */ 'g',        'b',        KBD_NOKEY,    '^',
  267. /* dc */ 'y',        'h',        'n',        KBD_NOKEY,
  268. /* e0 */ '&',        'u',        'j',        'm',
  269. /* e4 */ KBD_NOKEY,    '*',        'i',        'k',
  270. /* e8 */ ',',        KBD_NOKEY,    '(',        'o',
  271. /* ec */ 'l',        '.',        KBD_NOKEY,    ')',
  272. /* f0 */ 'p',        KBD_NOKEY,    ':',        '?',
  273. /* f4 */ KBD_NOKEY,    '+',        '}',        '|',
  274. /* f8 */ KBD_NOKEY,    '_',        '{',        '"',
  275. /* fc */ KBD_NOKEY,    KBD_NOKEY,    KBD_NOKEY,    KBD_NOKEY,
  276. };
  277.  
  278.  
  279. /*
  280.  * ----------------------------------------------------------------------------
  281.  *
  282.  * DevDC7085Reset --
  283.  *
  284.  *    Reset the chip.
  285.  *
  286.  * Results:
  287.  *    None.
  288.  *
  289.  * Side effects:
  290.  *    None.
  291.  *
  292.  * ----------------------------------------------------------------------------
  293.  */
  294. void
  295. DevDC7085Reset()
  296. {
  297.     *csrPtr = CSR_CLR;
  298.     while ((*csrPtr & CSR_CLR) != 0) {
  299.     }
  300.     *csrPtr = CSR_MSE | CSR_TIE | CSR_RIE;
  301. }
  302.  
  303. static void RecvIntr(), XmitIntr();
  304.  
  305. /*
  306.  * ----------------------------------------------------------------------------
  307.  *
  308.  * Dev_DC7085Interrupt --
  309.  *
  310.  *    Service an interrupt from the uart.
  311.  *
  312.  * Results:
  313.  *    None.
  314.  *
  315.  * Side effects:
  316.  *    Adds serial, keyboard or mouse events to the queue.
  317.  *
  318.  * ----------------------------------------------------------------------------
  319.  */
  320. ENTRY void
  321. Dev_DC7085Interrupt()
  322. {
  323.     MASTER_LOCK(&dc7085Mutex);
  324.  
  325.     if (*csrPtr & CSR_RDONE) {
  326.     RecvIntr();
  327.     }
  328.  
  329.     if (*csrPtr & CSR_TRDY) {
  330.     XmitIntr();
  331.     }
  332.  
  333.     MASTER_UNLOCK(&dc7085Mutex);
  334. }
  335.  
  336. static Boolean    shiftDown = FALSE;
  337. static Boolean    ctrlDown = FALSE;
  338. static Boolean    consoleCmd = FALSE;
  339. static unsigned char lastChar = 0;
  340. static Time    consoleCmdTime;
  341.  
  342.  
  343. /*
  344.  *----------------------------------------------------------------------
  345.  *
  346.  * RecvIntr --
  347.  *
  348.  *    Process a received character.
  349.  *
  350.  * Results:
  351.  *    None.
  352.  *
  353.  * Side effects:
  354.  *    Events added to the queue.
  355.  *
  356.  *----------------------------------------------------------------------
  357.  */
  358. ENTRY static void
  359. RecvIntr()
  360. {
  361.     unsigned short    recvBuf;
  362.     unsigned char    ch;
  363.     unsigned char    asciiChar;
  364.  
  365.     while (*csrPtr & CSR_RDONE) {
  366.     recvBuf = *rBufPtr;
  367.     ch = recvBuf & 0xFF;
  368.  
  369.     switch ((recvBuf & RBUF_LINE_NUM) >> RBUF_LINE_NUM_SHIFT) {
  370.         case KBD_PORT: {
  371.         if (devGraphicsOpen && !devDivertXInput) {
  372.             MASTER_UNLOCK(&dc7085Mutex);
  373.             DevGraphicsKbdIntr(ch);
  374.             MASTER_LOCK(&dc7085Mutex);
  375.             break;
  376.         }
  377.         if (ch != KEY_REPEAT) {
  378.             if (ch == KEY_UP) {
  379.             shiftDown = FALSE;
  380.             ctrlDown = FALSE;
  381.             break;
  382.             } else {
  383.             if (ch == KEY_SHIFT) {
  384.                 shiftDown = TRUE;
  385.                 break;
  386.             } else if (ch == KEY_CONTROL) {
  387.                 ctrlDown = TRUE;
  388.                 break;
  389.             } else if (ch == KEY_COMMAND) {
  390.                 consoleCmd = TRUE;
  391.                 Timer_GetTimeOfDay(&consoleCmdTime, (int *)NIL,
  392.                            (Boolean *)NIL);
  393.                 break;
  394.             }
  395.             }
  396.             lastChar = ch;
  397.         } else {
  398.             ch = lastChar;
  399.         }
  400.  
  401.         asciiChar = DevDC7085TranslateKey(ch, shiftDown, ctrlDown);
  402.         if (asciiChar != -1) {
  403.             if (consoleCmd) {
  404.             Time curTime, diff;
  405.  
  406.             consoleCmd = FALSE;
  407.             Timer_GetTimeOfDay(&curTime, (int *)NIL,(Boolean *)NIL);
  408.             Time_Subtract(curTime, consoleCmdTime, &diff);
  409.             if (diff.seconds <= CONSOLE_CMD_INTERVAL) {
  410.                 Dev_InvokeConsoleCmd(asciiChar);
  411.             } else {
  412.                 (*devKeyboard.inputProc)(devKeyboard.inputData, 
  413.                              asciiChar);
  414.             }
  415.             } else {
  416.             (*devKeyboard.inputProc)(devKeyboard.inputData, 
  417.                          asciiChar);
  418.             }
  419.         }
  420.         break;
  421.         }
  422.         case MOUSE_PORT:
  423.         if (devGraphicsOpen && !devDivertXInput) {
  424.             MASTER_UNLOCK(&dc7085Mutex);
  425.             DevGraphicsMouseIntr(ch);
  426.             MASTER_LOCK(&dc7085Mutex);
  427.         }
  428.         break;
  429.         case MODEM_PORT:
  430.         (*devSerialA.inputProc)(devSerialA.inputData, ch);
  431.         break;
  432.         case PRINTER_PORT:
  433.         (*devSerialB.inputProc)(devSerialB.inputData, ch);
  434.         break;
  435.     }
  436.     }
  437. }
  438.  
  439.  
  440. /*
  441.  *----------------------------------------------------------------------
  442.  *
  443.  * DevDC7085TranslateKey --
  444.  *
  445.  *    Translate a key code to an ascii character.
  446.  *
  447.  * Results:
  448.  *    The ascii character, -1 if couldn't translate it.
  449.  *
  450.  * Side effects:
  451.  *    None.
  452.  *
  453.  *----------------------------------------------------------------------
  454.  */
  455. char 
  456. DevDC7085TranslateKey(ch, shiftDown, ctrlDown)
  457.     unsigned char    ch;
  458.     Boolean    shiftDown;
  459.     Boolean    ctrlDown;
  460. {
  461.     char asciiChar;
  462.  
  463.     if (shiftDown) {
  464.     asciiChar = shiftedAscii[ch];
  465.     } else {
  466.     asciiChar = unshiftedAscii[ch];
  467.     }
  468.     if (asciiChar >= KBD_NOKEY) {
  469.     /*
  470.      * A function key was typed - ignore it.
  471.      */
  472.     return(-1);
  473.     } else if (asciiChar > KBD_MAX_VALUE) {
  474.     printf("DevDC7085TranslateKey: Bad key code raw: %d, mapped: %d\n",
  475.             ch, asciiChar);
  476.     return(-1);
  477.     } else {
  478.     if (asciiChar >= 'a' && asciiChar <= 'z') {
  479.         if (ctrlDown) {
  480.         asciiChar = asciiChar - 'a' + '';
  481.         } else if (shiftDown) {
  482.         asciiChar = asciiChar - 'a' + 'A';
  483.         }
  484.     } else if (ctrlDown) {
  485.         if (asciiChar >= '[' && asciiChar <= '_') {
  486.         asciiChar = asciiChar - '@';
  487.         } else if (asciiChar == ' ' || asciiChar == '@') {
  488.         asciiChar = '\0'; 
  489.         }
  490.     }
  491.     }
  492.  
  493.     return(asciiChar);
  494. }
  495.  
  496.  
  497. /*
  498.  *----------------------------------------------------------------------
  499.  *
  500.  * XmitIntr --
  501.  *
  502.  *    Handle a transmission interrupt.
  503.  *
  504.  * Results:
  505.  *    None.
  506.  *
  507.  * Side effects:
  508.  *    None.
  509.  *
  510.  *----------------------------------------------------------------------
  511.  */
  512. static void
  513. XmitIntr()
  514. {
  515.     char c;
  516.     int lineNum;
  517.  
  518.     if (!(*csrPtr & CSR_TRDY)) {
  519.     printf("XmitIntr: Spurious interrupt\n");
  520.     return;
  521.     }
  522.     lineNum = *csrPtr >> 8;
  523.     switch (lineNum & 0x3) {
  524.     case KBD_PORT:
  525.         break;
  526.     case MODEM_PORT:
  527.         c = (*devSerialA.outputProc)(devSerialA.outputData);
  528.         if (c == -1) {
  529.         *tcrPtr &= ~(1 << MODEM_PORT);
  530.         devSerialA.flags &= ~XMIT_ENABLED;
  531.         } else {
  532.         *tdrPtr = breakVal | c;
  533.         }
  534.         break;
  535.     case PRINTER_PORT:
  536.         c = (*devSerialB.outputProc)(devSerialB.outputData);
  537.         if (c == -1) {
  538.         *tcrPtr &= ~(1 << PRINTER_PORT);
  539.         devSerialB.flags &= ~XMIT_ENABLED;
  540.         } else {
  541.         *tdrPtr = breakVal | c;
  542.         }
  543.         break;
  544.     }
  545. }
  546.  
  547.  
  548. /*
  549.  *----------------------------------------------------------------------
  550.  *
  551.  * DevDC7085Activate --
  552.  *
  553.  *    This procedure is invoked in order to "activate" one half of a
  554.  *    DC7085 chip.
  555.  *
  556.  * Results:
  557.  *    None.
  558.  *
  559.  * Side effects:
  560.  *    The channel is re-initialized and the receiver is started.
  561.  *
  562.  *----------------------------------------------------------------------
  563.  */
  564. ENTRY void
  565. DevDC7085Activate(dcPtr)
  566.     register DevDC7085 *dcPtr;        /* Information about the device. */
  567. {
  568.     MASTER_LOCK(&dc7085Mutex);
  569.  
  570.     switch (dcPtr->port) {
  571.     case KBD_PORT:
  572.         if (!(dcPtr->flags & LINE_ACTIVE)) {
  573.         *lprPtr = LPR_RXENAB | LPR_B4800 | LPR_8_BIT_CHAR | KBD_PORT;
  574.         dcPtr->flags |= LINE_ACTIVE;
  575.         }
  576.         break;
  577.     case MODEM_PORT:
  578.     case PRINTER_PORT:
  579.         if (!(dcPtr->flags & LINE_ACTIVE)) {
  580.         *lprPtr = LPR_RXENAB | BaudToReg(dcPtr->baud) | 
  581.                  LPR_8_BIT_CHAR | dcPtr->port;
  582.         dcPtr->flags |= LINE_ACTIVE;
  583.         }
  584.         break;
  585.     }
  586.  
  587.     MASTER_UNLOCK(&dc7085Mutex);
  588. }
  589.  
  590.  
  591. /*
  592.  *----------------------------------------------------------------------
  593.  *
  594.  * DevDC7085RawProc --
  595.  *
  596.  *    This procedure is called back from the Td module as a raw
  597.  *    control procedure.
  598.  *
  599.  * Results:
  600.  *    The return value is the number of bytes returned to the caller
  601.  *    at outBuffer.
  602.  *
  603.  * Side effects:
  604.  *    Depends on the control operation.  Most likely effect is to
  605.  *    start transferring output data.
  606.  *
  607.  *----------------------------------------------------------------------
  608.  */
  609.  
  610. /* ARGSUSED */
  611. ENTRY int
  612. DevDC7085RawProc(dcPtr, operation, inBufSize, inBuffer, outBufSize, outBuffer)
  613.     register DevDC7085 *dcPtr;    /* Our information about device. */
  614.     int operation;        /* What to do:  TD_RAW_OUTPUT_READY etc. */
  615.     int inBufSize;        /* Size of input buffer for operation. */
  616.     char *inBuffer;        /* Input buffer. */
  617.     int outBufSize;        /* Size of output buffer for operation. */
  618.     char *outBuffer;        /* Output buffer. */
  619. {
  620.     int result = 0;
  621.  
  622.     MASTER_LOCK(&dc7085Mutex);
  623.  
  624.     switch (operation) {
  625.     case TD_RAW_START_BREAK:
  626.         breakVal |= 1 << (dcPtr->port + 8);
  627.         *tdrPtr = breakVal;
  628.         break;
  629.  
  630.     case TD_RAW_STOP_BREAK:
  631.         breakVal &= ~(1 << (dcPtr->port + 8));
  632.         *tdrPtr = breakVal;
  633.         break;
  634.  
  635.     case TD_RAW_SET_DTR:
  636.         if (dcPtr->port == MODEM_PORT) {
  637.         *tcrPtr |= TCR_DTR2;
  638.         }
  639.         break;
  640.  
  641.     case TD_RAW_CLEAR_DTR:
  642.         if (dcPtr->port == MODEM_PORT) {
  643.         *tcrPtr &= ~TCR_DTR2;
  644.         }
  645.         break;
  646.  
  647.     case TD_RAW_SHUTDOWN:
  648.         if (dcPtr->flags & LINE_ACTIVE) {
  649.         *lprPtr = dcPtr->port;
  650.         dcPtr->flags &= ~LINE_ACTIVE;
  651.         *tcrPtr &= ~(1 << dcPtr->port);
  652.         }
  653.         break;
  654.  
  655.     case TD_RAW_OUTPUT_READY:
  656.         if (!(dcPtr->flags & XMIT_ENABLED)) {
  657.         *tcrPtr |= 1 << dcPtr->port;
  658.         dcPtr->flags |= XMIT_ENABLED;
  659.         }
  660.         break;
  661.  
  662.     case TD_RAW_FLUSH_OUTPUT:
  663.         while ((*dcPtr->outputProc)(dcPtr->outputData) != -1) {
  664.         /* do nothing */
  665.         }
  666.         break;
  667.  
  668.     case TD_RAW_FLOW_CHARS:
  669.         /* Ignore flow-control chars. */
  670.         break;
  671.  
  672.     case TD_RAW_SET_BAUD_RATE: {
  673.         Td_BaudRate *brPtr;
  674.         int        i;
  675.  
  676.         /*
  677.          * Map the baud rate from an sgttyb constant to an actual
  678.          * number.  Return the value we actually set things to.
  679.          */
  680.  
  681.         brPtr = (Td_BaudRate *) inBuffer;
  682.         for (i = 0; baudMap[i].baud != -1; i++) {
  683.         if (baudMap[i].sgttybVal == brPtr->ospeed) {
  684.             dcPtr->baud = baudMap[i].baud;
  685.             break;
  686.         }
  687.         }
  688.         switch (dcPtr->port) {
  689.         case MODEM_PORT:
  690.             *lprPtr = LPR_RXENAB | BaudToReg(dcPtr->baud) | 
  691.                  LPR_8_BIT_CHAR | MODEM_PORT;
  692.             break;
  693.         case PRINTER_PORT:
  694.             *lprPtr = LPR_RXENAB | BaudToReg(dcPtr->baud) |
  695.                  LPR_8_BIT_CHAR | PRINTER_PORT;
  696.             break;
  697.         }
  698.  
  699.         /*
  700.          * Fall through to next arm of case to return current
  701.          * settings.
  702.          */
  703.     }
  704.  
  705.     case TD_RAW_GET_BAUD_RATE: {
  706.         int i;
  707.         Td_BaudRate *brPtr;
  708.  
  709.         brPtr = (Td_BaudRate *) outBuffer;
  710.         if (outBufSize >= sizeof(Td_BaudRate)) {
  711.         for (i = 0; baudMap[i].baud != -1; i++) {
  712.             if (baudMap[i].baud == dcPtr->baud) {
  713.             brPtr->ispeed = brPtr->ospeed = baudMap[i].sgttybVal;
  714.             result = sizeof(Td_BaudRate);
  715.             }
  716.         }
  717.         }
  718.         break;
  719.     }
  720.     }
  721.     MASTER_UNLOCK(&dc7085Mutex);
  722.     return result;
  723. }
  724.  
  725.  
  726. /*
  727.  *----------------------------------------------------------------------
  728.  *
  729.  * BaudToReg --
  730.  *
  731.  *    Map from a raw baud rate to the value to shove into the register.
  732.  *
  733.  * Results:
  734.  *    The baud value to shove into the register.
  735.  *
  736.  * Side effects:
  737.  *    None.
  738.  *
  739.  *----------------------------------------------------------------------
  740.  */
  741. int
  742. BaudToReg(baud)
  743.     int    baud;
  744. {
  745.     int    i = 0;
  746.  
  747.     while (baudMap[i].baud != baud && baudMap[i].baud != -1) {
  748.     i++;
  749.     }
  750.     return(baudMap[i].regVal);
  751. }
  752.  
  753.  
  754. /*
  755.  * ----------------------------------------------------------------------------
  756.  *
  757.  * DevDC7085MouseInit --
  758.  *
  759.  *    Initialize the mouse.
  760.  *
  761.  * Results:
  762.  *    None.
  763.  *
  764.  * Side effects:
  765.  *    The mouse is initialized.
  766.  *
  767.  * ----------------------------------------------------------------------------
  768.  */
  769. ENTRY void
  770. DevDC7085MouseInit()
  771. {
  772.     MASTER_LOCK(&dc7085Mutex);
  773.  
  774.     *lprPtr = LPR_RXENAB | LPR_B4800 | LPR_OPAR | LPR_PARENB |
  775.                LPR_8_BIT_CHAR | MOUSE_PORT;
  776.  
  777.     MASTER_UNLOCK(&dc7085Mutex);
  778. }
  779.  
  780.  
  781. /*
  782.  * ----------------------------------------------------------------------------
  783.  *
  784.  * DevDC7085MousePutCh --
  785.  *
  786.  *    Write a character to the mouse.  This is only called at initialization
  787.  *    time.
  788.  *
  789.  * Results:
  790.  *    None.
  791.  *
  792.  * Side effects:
  793.  *    A character is written to the mouse.
  794.  *
  795.  * ----------------------------------------------------------------------------
  796.  */
  797. ENTRY void
  798. DevDC7085MousePutCh(c)
  799.     int    c;
  800. {
  801.     register    int    timeout;
  802.     register    int    reg;
  803.  
  804.     MASTER_LOCK(&dc7085Mutex);
  805.  
  806.     reg = *tcrPtr;
  807.     *tcrPtr = 0x2;
  808.     timeout = 60000;
  809.  
  810.     for (timeout = 60000;
  811.      (!(*csrPtr & CSR_TRDY) || (*csrPtr & CSR_TX_LINE_NUM) != 0x100) &&
  812.          timeout > 0;
  813.      timeout--) {
  814.     }
  815.     *tdrPtr = c & 0xff;
  816.     MACH_DELAY(50000);
  817.     *tcrPtr = reg;
  818.  
  819.     MASTER_UNLOCK(&dc7085Mutex);
  820. }
  821.  
  822.  
  823. /*
  824.  * ----------------------------------------------------------------------------
  825.  *
  826.  * DevDC7085MouseGetCh --
  827.  *
  828.  *    Read a character from the mouse.  This is only called at
  829.  *    initialization time.
  830.  *
  831.  * Results:
  832.  *    A character read from the mouse, -1 if we timed out waiting.
  833.  *
  834.  * Side effects:
  835.  *    None.
  836.  *
  837.  * ----------------------------------------------------------------------------
  838.  */
  839. ENTRY int
  840. DevDC7085MouseGetCh()
  841. {
  842.     register int        timeout;
  843.     register unsigned short    c;
  844.  
  845.     MASTER_LOCK(&dc7085Mutex);
  846.  
  847.     for (timeout = 1000000; timeout > 0; timeout--) {
  848.     if (*csrPtr & CSR_RDONE) {
  849.         c = *rBufPtr;
  850.         MACH_DELAY(50000);
  851.         if (((c >> 8) & 03) != 1) {
  852.         continue;
  853.         }
  854.         MASTER_UNLOCK(&dc7085Mutex);
  855.         return(c & 0xff);
  856.     }
  857.     }
  858.     MASTER_UNLOCK(&dc7085Mutex);
  859.  
  860.     return(-1);
  861. }
  862.  
  863.  
  864. /*
  865.  * ----------------------------------------------------------------------------
  866.  *
  867.  * DevDC7085KBDPutc --
  868.  *
  869.  *    Put a character out to the keyboard.
  870.  *
  871.  * Results:
  872.  *    None.
  873.  *
  874.  * Side effects:
  875.  *    A character is written to the keyboard.
  876.  *
  877.  * ----------------------------------------------------------------------------
  878.  */
  879. ENTRY void
  880. DevDC7085KBDPutc(c)
  881.     register int c;
  882. {
  883.     register unsigned    short    tcr;
  884.     register int    timeout;
  885.     int            line;
  886.  
  887.     MASTER_LOCK(&dc7085Mutex);
  888.  
  889.     tcr = *tcrPtr & 1;
  890.     *tcrPtr |= 1;
  891.     while (1) {
  892.         timeout = 1000000;
  893.         while (!(*csrPtr & CSR_TRDY) && timeout > 0) {
  894.             timeout--;
  895.         }
  896.         if (timeout == 0) {
  897.             break;
  898.         }
  899.         line = (*csrPtr >> 8) & 3;
  900.         if (line != 0) {
  901.             tcr |= 1 << line;
  902.             *tcrPtr &= ~(1 << line);
  903.             continue;
  904.         }
  905.         *tdrPtr = breakVal | (c & 0xff);
  906.         MACH_DELAY(5);
  907.         while (1) {
  908.             while (!(*csrPtr & CSR_TRDY)) {
  909.             }
  910.             line = (*csrPtr >> 8) & 3;
  911.             if (line != 0) {
  912.                 tcr |= 1 << line;
  913.                 *tcrPtr &= ~(1 << line);
  914.                 continue;
  915.             }
  916.             break;
  917.         }
  918.         break;
  919.     }
  920.     *tcrPtr &= ~1;
  921.     if (tcr != 0) {
  922.     *tcrPtr |= tcr;
  923.     }
  924.  
  925.     MASTER_UNLOCK(&dc7085Mutex);
  926. }
  927.  
  928.